<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\captcha\Captcha;
use yii\widgets\ActiveForm;
use frontend\models\operate\User;
$this->title='发布问题';
    $session = yii::$app->session;
    $user_id = $session->get('user_id');
    if(!empty($user_id))
    {
        $user = User::find()->select("user_id,user_name,user_thumb")->where("user_id=$user_id")->asarray()->one();
    }
    else
    {
        $user = "";
    }
?>
<link href="/static/css/public-same.css" rel="stylesheet">
<link href="/static/css/question.css" rel="stylesheet">
<style type="text/css">
    .ibox-body .control-label {
        text-align: left;
        font-weight: 400;
        color: #666;
    }
    .form-horizontal{
        border-top: 1px solid #ECECEC;
        margin-top: 10px;
        padding-top: 20px;
    }
    .iPhone-num .ipt {
    float: left;
    padding: 10px;
    width: 100px;
    }
    #myEditor{
        height: 300px;
    }
</style>
<?= Html::jsFile('/ueditor/ueditor.config.js')?>
<?= Html::jsFile('/ueditor/_examples/editor_api.js')?>
<div class="block-nav-banner">
<div class="container">
<ul class="list-inline zy-list-inline">
<li><a href="<?= Url::to(['questions/index'])?>">问答</a></li>
<li class="active"><a href="<?= Url::to(['questions/release'])?>">发布问题</a></li>
</ul>
</div>
</div>
<!-- main-area -->
<div class="main-area QA-area" style=" background: #f5f5f5;">
<div class="container">
<div class="column-layout">
<!-- main-area-left start  -->

<div style="" class="column-col main-area-left">
    <div style="" class="main-area-leftin">

        <!-- 发布问题 -->
        <div style="" class="ibox">
            <div class="ibox-head">
                <div class="ibox-tit-text">发布问题</div>
            </div>
            <div style="" class="ibox-body ">
                <?php $form = ActiveForm::begin([
                                'options'=>['class'=>'form-horizontal'],
                                'action' => ['questions/release'],
                                'method'=>'post',
                        ])?>
                    <!--标题-->
                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>标题</label>
                        <div class="col-sm-11">
                            <input class="form-control" id="form-title" maxlength="40" name="title" placeholder="请给您的问题起个好标题 ..." rows="1" type="text">
                            
                        </div>
                    </div>
                    
                    <!--内容-->
                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>内容</label>
                        <div class="col-sm-11">
                        <textarea  id="myEditor"></textarea>
                            
                        </div>
                    </div>
                    <div class="form-group">
                        
                    </div>
                     <div class="form-group">
                        
                    </div>
                     <div class="form-group">
                        
                    </div>
                    <!--标签-->
                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>标签</label>
                        <div class="col-sm-11">
                            <div class="add-tag" style=" border: 1px solid #ccc; border-radius: 2px; overflow: hidden;">
                                <div class="hot-tag-box">
                                        
                                </div>
                                <input id="inpTags" autocomplete="off" m='<?php 
                        $arr = "";
                        foreach ($labels as $key => $label) {
                            $name = $label['queslabel_name'];
                            $label_id = $label['queslabel_id'];
                            $arr[$name]=$label_id; 
                        }
                        echo json_encode($arr)?>' class="form-control" placeholder="直接输入可过滤标签，最多打上3个标签" type="text">
                            </div>
                            
                            <!--输入文字可联想搜索你想用的标签，最多打上3个标签，用空格隔开-->
                            
                        </div>
                    </div>

                    <!--验证码-->
                    <div class="form-group">
                        <label for="" class="col-sm-1 control-label"><span class="red">*</span>验证码</label>
                        <div class="col-sm-11">
                        <div class="comm-reply-foot">
                        <?= $form->field($model, 'verifyCode', [
                                'options' => ['class' => ''],
                            ])->widget(Captcha::className(),[
                               'template' => '<p class="iPhone-num">{image}<span class="img-num">{input}</span></p>',
                               'imageOptions' => ['alt' => '验证码'],
                               'captchaAction' => 'questions/captcha',
                               'options' =>['placeholder' => '请输入验证码', 'class' => 'ipt'],
                            ]); ?>
                            
                            
                        
                        
                        </div>
                        
                            
                        </div>
                    </div>
                    
                    <div class="form-group">
                    <?php if(empty($user)){?>
                        <div class="col-sm-offset-1 col-sm-11">
                            <button type="button" class="btn btn-release">发布问题</button>
                        </div>
                    <?php }else{?>
                        <div class="col-sm-offset-1 col-sm-11">
                            <button type="submit" class="btn">发布问题</button>
                        </div>
                    <?php }?>    
                    </div>
                <?php $form = ActiveForm::end()?>
            </div>
        </div>

    </div>
</div>


<!-- main-area-left end  -->
<!-- main-area-right start  -->
<?php echo $this->render('common')?>
<!-- main-area-right end  -->
</div>
</div>
</div>
<div class="modal fade" id="jifen" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm modal-content zy_jifen">
        <p class="p1">问题发布成功！ </p>
        <p class="p2"><img src="/static/images/gold.png">积分+<span style="font-size: 18px;">2</span></p>
        <p class="p3">积累积分可兑换麦子商城礼品，敬请期待！</p>
        <img class="zy_jifen_img" src="/static/images/goldDown.gif">
        <a class="close"></a>
    </div>
</div>
</div>
<script type="text/javascript">
var ue = UE.getEditor('myEditor');

var input_tags=[];

var prefetched_tags =$.parseJSON($("#inpTags").attr("m"));


/*调用登录*/
    $(".btn-release").click(function(){
        login_popup()
    })
</script>
<script type="text/javascript" src="/static/js/release.js"></script>

